package com.bai.utils;

public class ParseUtils {

    public static String formatToSqlName(String fieldName){
        StringBuffer sb = new StringBuffer();
        char[] ch = fieldName.toCharArray();
        for (char c:ch){
            sb.append(upChar(c));
        }
        return sb.toString();
    }

    public static String upChar(char c){
        if(c>='a' && c<='z') {
            return String.valueOf(c).toUpperCase();
        }else if(c>='A' && c<='Z') {
            return "_"+String.valueOf(c).toUpperCase();
        }else if(c>='0' && c<='9'){
            return String.valueOf(c).toUpperCase();
        }else{
            return "";
        }
    }

    public static String lowerFirst(String name){
        char[] chars = name.toCharArray();
        chars[0] += 32;
        return String.valueOf(chars);
    }
}
